package lesson17;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;

public class MyThreadLocal {

    private static ThreadLocal<AtomicInteger> count = new ThreadLocal<>();

    static ExecutorService executorService = Executors.newFixedThreadPool(3);

    public static void main(String[] args) throws InterruptedException {

        Thread thread = new Thread(() ->{
            if(count.get() == null){
                count.set(new AtomicInteger(0));
            }
            System.out.println(Thread.currentThread().getName() +" : " + count.get().incrementAndGet());
        });

        for(int i = 0; i < 10; i++){
            executorService.execute(thread);
        }

        Thread.sleep(1000);
    }
}
